package com.chanyachting.emall.action.lease;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Rentyacht;
import com.chanyachting.emall.form.RentyachtForm;
import com.chanyachting.emall.service.RentyachtService;
import com.chanyachting.emall.serviceImpl.RentyachtServiceImpl;

public class QueryCatamaranRentAction  extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		//一般页面记录数
		int COMMON_PAGE_SIZE = 20;
		//主页表示记录数
		int INDEX_PAGE_SIZE = 6;
		//双体船租赁
		String RENT_YACHT_TYPE = "95";
		
		RentyachtService ryService = new RentyachtServiceImpl();
		RentyachtForm rf = (RentyachtForm)form;
		
		int currentPage = rf.getCurrentPage();
		int pageSize;
		
		if ("1".equals(rf.getPageType())) {
			pageSize = COMMON_PAGE_SIZE;
		} else {
			pageSize = INDEX_PAGE_SIZE;
		}
		int pageCount = ryService.QueryAppointRentyachtCount("01",RENT_YACHT_TYPE)/pageSize;
		if (ryService.QueryAppointRentyachtCount("01",RENT_YACHT_TYPE)%pageSize > 0) {
			pageCount = pageCount + 1;
		}
		
		if (currentPage < 1) {
			currentPage = 1;
		} else if (currentPage > pageCount) {
			return mapping.findForward("error");
		}
		List<Rentyacht> ryList = ryService.QueryAppointRentyacht(currentPage, pageSize,RENT_YACHT_TYPE);
		rf.setRyList(ryList);
		rf.setPageCount(pageCount);
		
		return mapping.findForward("toCatamaranRentyacht");
	}
}
